package com.shangxia.monomer.study.designPatterns.behavioralType.strategy;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: monomer
 * @ClassName: StrategyDemoSed
 * @Time: 2021/8/1
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class StrategyDemoSed {
    public static void main(String[] args) {

        System.out.println(new Content(new SANormal()).getResult(new Cash(100.0)));
        System.out.println(new Content(new SADiscount(0.8)).getResult(new Cash(100.0)));
        System.out.println(new Content(new SAFullReduction(300.0, 100.0)).getResult(new Cash(600.0)));

    }

}

@Data
@AllArgsConstructor
class Cash {
    private Double originalPrice;
}

@Data
@AllArgsConstructor
class Content {

    private StrategyAlgorithm strategy;

    public Double getResult(Cash cash) {
        return strategy.getResult(cash.getOriginalPrice());
    }
}

interface StrategyAlgorithm {
    Double getResult(Double originalPrice);
}

class SANormal implements StrategyAlgorithm {

    @Override
    public Double getResult(Double originalPrice) {
        return originalPrice;
    }
}

@Data
@AllArgsConstructor
class SADiscount implements StrategyAlgorithm {
    private Double discount;

    @Override
    public Double getResult(Double originalPrice) {
        return originalPrice * discount;
    }
}

@Data
@AllArgsConstructor
class SAFullReduction implements StrategyAlgorithm {

    private Double fullPrice;
    private Double reduceMoney;

    @Override
    public Double getResult(Double originalPrice) {
        if (originalPrice > fullPrice) {
            return originalPrice - (Math.floor(originalPrice / fullPrice) * reduceMoney);
        }
        return originalPrice;
    }
}